import Vue from 'vue'
import VueRouter from 'vue-router'
import a from "@/store/index.js"




// import { component } from 'vue/types/umd'

console.log(a.getters['login/loginToken']);
console.log(a);

Vue.use(VueRouter)

const routes = [

  {
    path: "",
    redirect: "/index",
  },

  // {
  //   path:'/',
  //   component:()=>import("@/views/Home.vue")
  // },

  // {
  //   path:'/category',
  //   component:()=>import("@/views/category/Category.vue")
  // },

  // {
  //   path: '/cart',
  //   name: "Cart",
  //   component: () => import("@/views/cart/Cart.vue")
  // },
  // {
  //   path:'/user',
  //   component:()=> import("@/views/user/User.vue")
  // },
  {
    path: '/',
    name: "Home",
    
    component: () => import("@/views/Home.vue"),
    children: [
      {
        path: 'index',
        name: "Index",
        meta:{
          title:"首页"
        },
        component: () => import("@/views/index/Index.vue")
      },
     
      {
        path: 'cart',
        name: "Cart",
       
        meta:{nendLogin:true,title:"购物车"},
        component: () => import("@/views/cart/Cart.vue")
      },
      {
        path: 'user',
        name: "User",
        
        meta:{nendLogin:true,title:"个人中心"},
        component: () => import("@/views/user/User.vue"),
        
      },
      {
        path: 'category',
        name: "Category",
        meta:{
          title:"全部分类"
        },
        component: () => import("@/views/category/Category.vue")
      },

    ]
  },

  {
    path: "/login",
    name: "Login",
    meta:{
      title:"登录注册"
    },
    component: () => import("@/views/login/Login.vue")
  },


  // 用户页子路由
  {
    path:"/user/data",
    meta:{nendLogin:true,title:"修改信息"},
    component: () => import("@/views/user/data/Data.vue"),
  },
  {
    path:"/user/vip",
    meta:{nendLogin:true,title:"我的会员"},
    component: () => import("@/views/user/vip/Vip.vue"),
  },
  {
    path:"/user/user_promotion",
    meta:{nendLogin:true,title:"我的推广"},
    component: () => import("@/views/user/promotion/UserPromotion.vue"),
  },
  {
    path:"/user/account",
    meta:{nendLogin:true,title:"我的账户"},
    component: () => import("@/views/user/account/Account.vue"),
  },
  // 用户地址页
  {
    path:"/user/add_manage",
 
      meta:{nendLogin:true,title:"我的地址列表"},
    
    component: () => import("@/views/user/address/AddManage.vue"),
  },
  {
    path:"/user/add_address/:id?",
   
      meta:{nendLogin:true,title:"修改地址"},
    
    component: () => import("@/views/user/address/AddAddress.vue"),
  },

  // 修改密码
  {
    path:"/change_password",
   
      meta:{nendLogin:true,title:"修改密码"},
    
    component:()=>import("@/views/changepassword/ChangePassword.vue")
  },

  
  // 订单页
  {
    path:"/order/list/:type",
    
   
      meta:{nendLogin:true,title:"我的订单"},
    
    component: () => import("@/views/order/OrderList.vue"),
  },
  {
    path:"/order/detail/:id",
    meta:{nendLogin:true,title:"订单详情"},
    component:()=>import("@/views/order/detail/OrderDetail.vue")
  },
  
  // 更多页
  {
    path:"/hot_new_goods/:id",

      meta:{nendLogin:true,title:"更多推荐"},
   
    component:()=> import("@/views/hotmore/HotMore.vue")
  },

  // 详情页
  {
    path:"/detail/:id",
    name:"Detail",
    
      meta:{nendLogin:true,title:"商品详情"},
    
    component:()=>import("@/views/detail/Detail.vue")
  },

  // 搜索页
  {
    path:"/search",
    name:"Search",
 
      meta:{title:"搜索"},
 
    component:()=>import("@/views/search/Search.vue")
  },

  // 列表页
  {
    path:"/goods_list",
    name:"GoodsList",
  
      meta:{title:"商品列表页"},

    component:()=>import("@/views/goodsList/GoodsList.vue")
  },

  // 收藏页
  {
    path:"/collect",
    name:"Collect",
   
      meta:{nendLogin:true,title:"我的收藏"},
    
    component:()=>import("@/views/collect/Collect.vue")
  },

  // 订单提交
  {
    path:"/order/submit/:id",
    name:"Submit",
   
      meta:{nendLogin:true,title:"提交订单"},
    
    component:()=>import("@/views/order/submit/Submit.vue")
  },
  // 支付成功
  {
    path:"/order/status/:id/:key?",
    
      meta:{nendLogin:true,title:"订单创建成功"},
    
    component:()=>import("@/views/order/success/OrderSuccess.vue")
},
  // 退回订单
  {
    path:"/order/refund/:id",
    name:"Refund",
   
      meta:{nendLogin:true,title:"退回订单"},
 
    component:()=>import("@/views/order/refund/OrderRefund.vue")
  },
  // 退单列表
  {
    path:"/order/refund_list",
    name:"RefundList",
  
      meta:{nendLogin:true,title:"退单列表"},

    component:()=>import("@/views/order/refund/OrderRefundList.vue")
  },
  // 找回密码 
  {
    path:"/psw",
    name:"Psw",
  
      meta:{title:"找回密码"},

    component:()=>import("@/views/login/PswComp.vue")
  }
]

const router = new VueRouter({
  routes
})



router.beforeEach(function (to, from, next) {
  
  if(to.meta.nendLogin && !a.getters['login/loginToken']){
    next('/login')
  }

  next()
  
  
})




export default router